package com.sskj.givecoin.v.activity;

import android.content.Context;
import android.content.Intent;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jkb.vcedittext.VerificationCodeEditText;
import com.sskj.givecoin.MyAppLication;
import com.sskj.givecoin.R;
import com.sskj.givecoin.common.App;
import com.sskj.givecoin.common.Constants;
import com.sskj.givecoin.m.bean.AseetListBean;
import com.sskj.givecoin.p.activity.GoogleLoginPresenter;
import com.sskj.givecoin.utils.ClickUtil;
import com.sskj.givecoin.utils.SPUtils;
import com.sskj.givecoin.utils.ToastUtil;
import com.sskj.givecoin.v.base.BaseActivity;

import butterknife.BindView;

/**
 * ProjectName：期权
 * DESC: (类描述) 用户开启谷歌认证--登录时校验谷歌验证码
 * Created by hqf on 2018/10/23 9:26
 * updateName:(修改人名称)
 * updateTime:(修改时间)
 * updateDesc:(修改内容)
 */
public class GoogleLoginActivity extends BaseActivity<GoogleLoginPresenter> {


    @BindView(R.id.b_title)
    TextView bTitle;
    @BindView(R.id.etVerificationCode)
    VerificationCodeEditText etVerificationCode;
    @BindView(R.id.google_b_layout)
    LinearLayout googleBLayout;
    @BindView(R.id.btn_next)
    Button btnNext;
    private int type;
    private AseetListBean.AseetBean item;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_google_login;
    }

    @Override
    public GoogleLoginPresenter getPresenter() {
        return new GoogleLoginPresenter();
    }

    @Override
    protected void onViewBinding() {
        super.onViewBinding();
        type = getIntent().getIntExtra("type", 0);
        if(1==type){
            item = (AseetListBean.AseetBean) getIntent().getSerializableExtra("item");
        }
        ClickUtil.click(btnNext, () -> {
            if (etVerificationCode.getText().toString().trim().length() < 6) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.strGoogleLoginActivity202));
                return;
            }
            mPresenter.verifyCode(etVerificationCode.getText().toString());
        });
    }

    public void updateUi() {
        finish();
        SPUtils.put(MyAppLication.getApplication(), Constants.SP_LOGIN_STATUS, true);
        if (0 == type) {
            startActivity(new Intent(this, MainActivity.class));
        }else{
            startActivity(new Intent(GoogleLoginActivity.this, WithdrawActivity.class).putExtra(Constants.INTENT_ASSET_ID, item.pid).putExtra(Constants.INTENT_ASSET_NAME, item.pname));
        }

    }

    public static void start(Context context, int type,AseetListBean.AseetBean item) {  // 0 代表带转到MainActivity  1代表跳转到提币界面
        Intent intent = new Intent(context, GoogleLoginActivity.class);
        intent.putExtra("type", type);
        intent.putExtra("item", item);
        context.startActivity(intent);
    }
}
